<template>
	<div class="contact_us_container">
		<div class="header">
			<h2>帮助我们</h2>
		</div>
		<div ref="content" class="content">
			<ck-editor v-model="noticeData.content"></ck-editor>
		</div>
		<div class="button">
			<el-button type="primary" @click="handleSaveData()">保存</el-button>
		</div>
	</div>
</template>

<script>
import { queryPageList, addNotice, updateNotice } from '@/api/basedata/sysNotice';
export default {
	data() {
		return {
			loading: false,
			noticeData: {}
		};
	},
	computed: {
		addOrEdit() {
			return Object.keys(this.noticeData).length === 0;
		}
	},
	mounted() {
		this.loading = true;
		this.getAboutUsData();
	},
	methods: {
		//获取数据
		async getAboutUsData() {
			let params = { page: 1, limit: 1, type: 5 };
			let result = await queryPageList(params).then(res => res.data);
			this.loading = false;
			if (result.code === '0') {
				this.noticeData = this.$detailData(result.data);
			}
		},

		//保存数据
		async handleSaveData() {
			let params = { ...this.noticeData };
			let callFunction = eval(this.addOrEdit ? addNotice : updateNotice);
			let result = await callFunction(params).then(res => res.data);
			if (result.code === '0') {
				this.$message.success('保存成功');
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.contact_us_container {
	display: flex;
	flex-direction: column;
	height: 100%;
	padding: 16px;
	box-sizing: border-box;
	.header {
		flex-shrink: 0;
		h2 {
			font-size: 20px;
			line-height: 1;
		}
	}
	.content {
		flex: 1;
		padding: 16px 0;
		overflow: hidden;
	}
	.button {
		flex-shrink: 0;
	}
}
</style>
